package logic

import (
	"context"
	"doctor-medicine-system/docrpc/docrpc"

	"doctor-medicine-system/api/internal/svc"
	"doctor-medicine-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DrugAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDrugAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DrugAddLogic {
	return &DrugAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DrugAddLogic) DrugAdd(req *types.DrugAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	updates, err := l.svcCtx.DocRpc.DrugAdd(l.ctx, &docrpc.DrugAddRequest{
		Norms:      req.Norms,
		Vendor:     req.Vendor,
		Indication: req.Indication,
		Dosage:     req.Dosage,
		Matter:     req.Matter,
		DocTocId:   req.DocTocId,
	})
	if err != nil {
		return &types.Response{
			Message: "添加失败",
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    updates,
	}, nil
}
